package com.ruoyi.web.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.domain.insect.InsectRecord;
import com.ruoyi.web.enums.AggreEnum;
import com.ruoyi.web.middleware.influxdb.Influxdb2Service;
import com.ruoyi.web.service.insect.InsectRecordService;
import com.ruoyi.web.task.WarningTask;
import com.ruoyi.web.utils.influxdb.DeviceAggreDataParam;
import com.ruoyi.web.utils.influxdb.DeviceData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/ztest")
public class ZTestController {

    @Autowired
    private Influxdb2Service influxdb2Service;

    @Autowired
    InsectRecordService insectRecordService;

    @Autowired
    WarningTask warningTask;


    @GetMapping("/max01")
    public R max01(String deviceId,Long productId, String factor,AggreEnum aggre)
    {
        DeviceAggreDataParam param = null;

        // param = DeviceAggreDataParam.getMonth(deviceId,productId,factor);

        List<DeviceData> deviceData = influxdb2Service.aggregateWindow(param);
        return R.ok(deviceData);
    }

    @GetMapping("/task")
    public R task()
    {
        warningTask.runFactor();
        return R.ok();
    }

    @GetMapping("/task3")
    public R task3()
    {
        warningTask.runInsect();
        return R.ok();
    }

    @GetMapping("/task4")
    public R task4()
    {
        warningTask.sendInsectNotice(null);
        warningTask.sendFactorNotice(null);
        return R.ok();
    }

}
